
#include "gmatlab.h"

// const gchar * g_type_name(GType);
void mexFunction(int nlhs, mxArray *lhs[], int nrhs, const mxArray *rhs[])
{
  GType gtype;
  
  // Check and convert arguments
  if (nrhs != 1) g_matlab_error("gmatlab:numArg", "g_type_name() takes 1 argument");
  if (nlhs != 1) g_matlab_error("gmatlab:numRet", "g_type_name() has 1 return value");
  switch (mxGetClassID(rhs[0]))
  {
    case MX_GLONG:
      gtype = (GType)(((glong*)mxGetData(rhs[0]))[0]);
      break;
    case MX_GPOINTER:
      gtype = (GType)(((gpointer*)mxGetData(rhs[0]))[0]);
      break;
    default:
      g_matlab_error("gmatlab:badType", "g_type_name: Arg 1 must be int, not %s", mxGetClassName(rhs[0]));
      break;
  }
  
  // Call function
  lhs[0] = g_matlab_mxArray_from_utf8(g_type_name(gtype));
}
